Clover coverage report - bexee - 0.1
Coverage timestamp: Do Dez 16 2004 13:24:06 CET
file stats: LOC: 197   Methods: 7
NCLOC: 125   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
PartnerLinkTypeDeserializer.java 50% 55.8% 57.1% 54.3%
coverage coverage
 1   
 /*
 2   
  * $Id: PartnerLinkTypeDeserializer.java,v 1.1 2004/12/15 14:18:21 patforna Exp $
 3   
  *
 4   
  * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
 5   
  * Berne University of Applied Sciences
 6   
  * School of Engineering and Information Technology
 7   
  * All rights reserved.
 8   
  */
 9   
 package bexee.wsdl.extensions.partnerlinktype;
 10   
 
 11   
 import java.io.PrintWriter;
 12   
 
 13   
 import javax.wsdl.Definition;
 14   
 import javax.wsdl.PortType;
 15   
 import javax.wsdl.WSDLException;
 16   
 import javax.wsdl.extensions.ExtensibilityElement;
 17   
 import javax.wsdl.extensions.ExtensionDeserializer;
 18   
 import javax.wsdl.extensions.ExtensionRegistry;
 19   
 import javax.wsdl.extensions.ExtensionSerializer;
 20   
 import javax.xml.namespace.QName;
 21   
 
 22   
 import org.w3c.dom.Element;
 23   
 import org.w3c.dom.Node;
 24   
 import org.w3c.dom.NodeList;
 25   
 
 26   
 import bexee.ecs.XML;
 27   
 import bexee.util.StringUtils;
 28   
 import bexee.wsdl.extensions.partnerlinktype.impl.RoleImpl;
 29   
 
 30   
 /**
 31   
  * This is a Serializer and a Deserializer as used by the JWSDL standard. It is
 32   
  * used serialization and deserialization of extension elements, i.e. in this
 33   
  * particular case it is used for the PartnerLinkType extension element added to
 34   
  * WSDL by the BPEL standard.
 35   
  * 
 36   
  * @author Pawel Kowalski
 37   
  * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:21 $
 38   
  */
 39   
 public class PartnerLinkTypeDeserializer implements ExtensionDeserializer,
 40   
         ExtensionSerializer {
 41   
 
 42   
     /**
 43   
      * Deserialize a PartnerLinkType from the xml element string.
 44   
      */
 45  16
     public ExtensibilityElement unmarshall(Class parentType, QName elementType,
 46   
             Element element, Definition definition, ExtensionRegistry extReg)
 47   
             throws WSDLException {
 48   
 
 49   
         // create new extension element, a PartnerLinkType
 50   
         //
 51  16
         PartnerLinkType partnerLType = (PartnerLinkType) extReg
 52   
                 .createExtension(parentType, elementType);
 53   
 
 54   
         // set the attributes
 55   
         //
 56  16
         partnerLType.setName(element.getAttribute("name"));
 57   
 
 58   
         // set children elements
 59   
         //
 60  16
         setRoles(partnerLType, element, definition);
 61   
 
 62  16
         return partnerLType;
 63   
     }
 64   
 
 65   
     /**
 66   
      * Serialize a PartnerLinkType to an xml string.
 67   
      */
 68  0
     public void marshall(Class parentType, QName elementType,
 69   
             ExtensibilityElement element, PrintWriter pw,
 70   
             Definition definition, ExtensionRegistry extReg)
 71   
             throws WSDLException {
 72   
 
 73  0
         PartnerLinkType linkType = (PartnerLinkType) element;
 74   
 
 75  0
         String prefix = getPrefix(definition, PartnerLinkTypeConstants.NS_URI);
 76   
 
 77  0
         String pLinkTypeElementName = prefix
 78   
                 + PartnerLinkTypeConstants.LOCAL_NAME;
 79  0
         String roleElementName = prefix + RoleConstants.LOCAL_NAME;
 80  0
         String portTypeElementName = prefix
 81   
                 + RoleConstants.PORT_TYPE_LOCAL_NAME;
 82   
 
 83  0
         XML plinkXml = (XML) new XML(pLinkTypeElementName).addXMLAttribute(
 84   
                 PartnerLinkTypeConstants.PLINK_TYPE_NAME, linkType.getName());
 85   
 
 86  0
         Role role;
 87  0
         if ((role = linkType.getMyRole()) != null) {
 88  0
             plinkXml.addElement(getRoleXMLNode(definition, role,
 89   
                     roleElementName, portTypeElementName));
 90   
         }
 91  0
         if ((role = linkType.getPartnerRole()) != null) {
 92  0
             plinkXml.addElement(getRoleXMLNode(definition, role,
 93   
                     roleElementName, portTypeElementName));
 94   
         }
 95   
 
 96  0
         pw.print(plinkXml.toString() + "\n");
 97   
 
 98   
     }
 99   
 
 100  0
     private XML getRoleXMLNode(Definition definition, Role role,
 101   
             String roleElementName, String portTypeElementName) {
 102   
 
 103  0
         XML roleXml = (XML) new XML(roleElementName).addXMLAttribute(
 104   
                 RoleConstants.ROLE_NAME, role.getName());
 105   
 
 106  0
         PortType portType = role.getPortType();
 107  0
         String portTypeName = getPrefix(definition, portType.getQName()
 108   
                 .getNamespaceURI())
 109   
                 + portType.getQName().getLocalPart();
 110  0
         XML portTypeXml = (XML) new XML(portTypeElementName).addXMLAttribute(
 111   
                 RoleConstants.PORT_TYPE_NAME, portTypeName);
 112   
 
 113  0
         roleXml.addElement(portTypeXml);
 114  0
         return roleXml;
 115   
     }
 116   
 
 117  0
     private String getPrefix(Definition definition, String namespaceURI) {
 118  0
         String prefix = definition.getPrefix(namespaceURI);
 119  0
         return (StringUtils.isNullOrEmpty(prefix) ? "" : prefix + ":");
 120   
     }
 121   
 
 122  16
     private void setRoles(PartnerLinkType partnerLType, Element element,
 123   
             Definition definition) throws WSDLException {
 124  16
         NodeList list = element.getChildNodes();
 125  16
         for (int i = 0; i < list.getLength(); i++) {
 126  48
             Node node = (Node) list.item(i);
 127  48
             if (node instanceof Element) {
 128  16
                 Element nodeElement = (Element) node;
 129  16
                 if (nodeElement.getLocalName().equals(RoleConstants.LOCAL_NAME)
 130   
                         && nodeElement.getNamespaceURI().equals(
 131   
                                 RoleConstants.NS_URI)) {
 132  16
                     Role role = new RoleImpl();
 133  16
                     role.setName(nodeElement
 134   
                             .getAttribute(RoleConstants.ROLE_NAME));
 135  16
                     setPortType(role, nodeElement, definition);
 136  16
                     if (partnerLType.getMyRole() == null) {
 137  16
                         partnerLType.setMyRole(role);
 138   
                     } else {
 139  0
                         partnerLType.setPartnerRole(role);
 140   
                     }
 141   
                 }
 142   
             }
 143   
         }
 144   
     }
 145   
 
 146  16
     private void setPortType(Role role, Element nodeElement,
 147   
             Definition definition) throws WSDLException {
 148  16
         role.setPortType(getPortType(definition, nodeElement));
 149   
     }
 150   
 
 151   
     /**
 152   
      * Extract the right PortType from the definition. The name of the PortType
 153   
      * is extracted from the following xml element:
 154   
      * 
 155   
      * &lt;role name=&quot;Buyer&quot;&gt; &lt;portType
 156   
      * name=&quot;buy:BuyerPortType&quot;/&gt; &lt;/role&gt;
 157   
      * 
 158   
      * @param roleElement
 159   
      * @return a PortType
 160   
      * @throws WSDLSemanticException
 161   
      */
 162  16
     private PortType getPortType(Definition definition, Element roleElement)
 163   
             throws WSDLException {
 164   
 
 165  16
         NodeList list = roleElement.getChildNodes();
 166  32
         for (int i = 0; i < list.getLength(); i++) {
 167  32
             Node node = (Node) list.item(i);
 168  32
             if (node instanceof Element) {
 169  16
                 Element nodeElement = (Element) node;
 170  16
                 if (nodeElement.getNamespaceURI().equals(RoleConstants.NS_URI)
 171   
                         && nodeElement.getLocalName().equals(
 172   
                                 RoleConstants.PORT_TYPE_LOCAL_NAME)) {
 173  16
                     Node portTypeNode = nodeElement
 174   
                             .getAttributeNode(PartnerLinkTypeConstants.PLINK_TYPE_NAME);
 175  16
                     String[] portTypeName = StringUtils.split(portTypeNode
 176   
                             .getNodeValue());
 177  16
                     portTypeName[0] = definition.getNamespace(portTypeName[0]);
 178  16
                     QName portTypeQName = new QName(portTypeName[0],
 179   
                             portTypeName[1]);
 180   
 
 181  16
                     PortType portType = definition.getPortType(portTypeQName);
 182  16
                     if (portType != null) {
 183  16
                         return portType;
 184   
                     } else {
 185   
                         // no such portType found in wsdl definition
 186  0
                         throw new WSDLException(WSDLException.INVALID_WSDL,
 187   
                                 "PortType: " + portTypeQName + " not found");
 188   
                     }
 189   
                 }
 190   
             }
 191   
         }
 192   
 
 193   
         // no such portType found in wsdl definition
 194  0
         throw new WSDLException(WSDLException.INVALID_WSDL,
 195   
                 "PortType not found");
 196   
     }
 197   
 }